#!/usr/bin/perl

use warnings;
use strict;

open (DATEBOOK, "datebook") or die $!;
my @lines;
foreach my $line (<DATEBOOK>) {
    chomp($line);
    push(@lines, $line);
}

print "Please enter a name:\n";
chomp(my $name = <STDIN>);
my @found_lines = grep(/$name/i, @lines);
my @found_numbers;
my $i = 0;
foreach (@found_lines) {
    my @splitted_line = split (":", $_);
    $found_numbers[$i] = $splitted_line[1];
    $i++;
}

foreach (@found_numbers) {
    print "$_\n";
}
printf ("Has found %d line(s).\n", ($#found_lines + 1));

close DATEBOOK;
